﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Zatify.WebUI.Infrastructure.Filters
{
    public class ZatifyAnonimousAccessRestrictFilter : ActionFilterAttribute, IActionFilter
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if ((filterContext.ActionDescriptor.ControllerDescriptor.ControllerName != "Anonymous") &&// && filterContext.ActionDescriptor.ActionName != "LoginAnonymous") &&
                (filterContext.HttpContext.Session["IsAnonimous"] == null || ((bool)filterContext.HttpContext.Session["IsAnonimous"])))
            {
                filterContext.Result = new RedirectResult("/Anonymous/Login");
            }

            base.OnActionExecuting(filterContext);
        }
    }
}